package fr.vahren.dotastrat.model;

import java.util.List;

import org.json.simple.JSONObject;

public abstract class D2SAbility {

	protected String name;

	protected int coolDown;

	protected int remainingCoolDown;

	protected int manaCost;

	protected int damage;

	protected int level;

	protected int levelMax;

	protected int id;

	protected int priority;
	
	protected int range;

	public void levelUp(D2SHeroUnit unit) {

		if (level < levelMax) {
			if (level == 0) {
				init();
			}
			level++;
			// level up effects
			levelUpEffects();
		}
	}

	protected abstract void levelUpEffects();

	protected abstract void init();

	public abstract void execute(D2SPlayer player, D2SMap map,
			D2SHeroUnit unit, List<D2SUnit> targetUnits, D2SZone targetZone);

	// GETTERS + SETTERS

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public int getCoolDown() {
		return coolDown;
	}

	public void setCoolDown(int coolDown) {
		this.coolDown = coolDown;
	}

	public int getRemainingCoolDown() {
		return remainingCoolDown;
	}

	public void setRemainingCoolDown(int remainingCoolDown) {
		this.remainingCoolDown = remainingCoolDown;
	}

	public int getManaCost() {
		return manaCost;
	}

	public void setManaCost(int manaCost) {
		this.manaCost = manaCost;
	}

	public int getDamage() {
		return damage;
	}

	public void setDamage(int damage) {
		this.damage = damage;
	}

	public int getLevel() {
		return level;
	}

	public void setLevel(int level) {
		this.level = level;
	}

	public int getLevelMax() {
		return levelMax;
	}

	public void setLevelMax(int levelMax) {
		this.levelMax = levelMax;
	}

	/**
	 * @return the id
	 */
	public int getId() {
		return id;
	}

	/**
	 * @param id
	 *            the id to set
	 */
	public void setId(int id) {
		this.id = id;
	}

	@SuppressWarnings("unchecked")
	public JSONObject generateInfo() {
		JSONObject a = new JSONObject();

		a.put("name", name);
		a.put("remainingCooldown", remainingCoolDown);
		a.put("id", id);
		a.put("level", level);

		return a;
	}

	public boolean isOnCooldown() {
		return remainingCoolDown > 0;
	}

	public int getPriority() {
		return priority;
	}

	public void setPriority(int priority) {
		this.priority = priority;
	}

	public int getRange(){
		return range;
	}

}
